package com.web.words;

import com.bean.Words;
import com.service.WordsService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class FindWordByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        WordsService service=new WordsService();

        int id=Integer.valueOf(req.getParameter("id"));
        try {
            List<Words> word=service.findWordById(id);
            req.getSession().setAttribute("word",word);
            req.getRequestDispatcher("/admin/word/view.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
